const MongoClient = require('mongodb').MongoClient

const url = 'mongodb://localhost:27017';

const dbName = 'demo'

// 封装数据库连接方法,连接成功掉用回调函数
function connect(callback){
    MongoClient.connect(url,function(err,client){
        if(err){
            console.log(err)
        }else{
            const db = client.db(dbName)
            callback && callback(db)
            client.close()
        }
    })
}

module.exports = {
    connect
}